package com.cc.study.annotation;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @Author C.
 * @Date 2019-05-02 23:32
 */
public class TestAnnotation {

    @Test
    public void demo01(){
        String xmlPath = "annotation.xml";
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        User user = (User) applicationContext.getBean("userId");
        System.out.println(user);
    }

    @Test
    public void demo02(){
        String xmlPath = "annotation.xml";
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        User user = (User) applicationContext.getBean("userId");
        System.out.println(user.getUsername());
    }

    @Test
    public void demo03(){
        String xmlPath = "annotation.xml";
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        User user = (User) applicationContext.getBean("userId");
        System.out.println(user.getUsername());
        System.out.println(user.getAddress().getAddr());
        System.out.println(user.getAddress().getTel());
    }


    @Test
    public void demo04(){
        String xmlPath = "annotation.xml";
        AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        User user = (User) applicationContext.getBean("userId");
        System.out.println(user.getUsername());
        System.out.println(user.getAddress().getAddr());
        System.out.println(user.getAddress().getTel());
        applicationContext.close();
    }

    @Test
    public void demo05(){
        String xmlPath = "annotation.xml";
        AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        User user1 = (User) applicationContext.getBean("userId");
        User user2 = (User) applicationContext.getBean("userId");
        System.out.println(user1);
        System.out.println(user2);
    }
}
